home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
threads
/
USysCalls.c
< prev
Wrap
C/C++ Source or Header
|
1992-02-18
|
17KB
|
911 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94062
endcopyright */
/*
* USysCalls.c
*
* Demers, December 7, 1990 9:12:40 am PST
* Hatakeyama, August 18, 1989 2:58:37 pm PDT
* Boehm, June 7, 1990 1:39:03 pm PDT
*
* Unix system calls for threads.
*
*/
#include <xr/ThreadsBackdoor.h>
#include <xr/UIO.h>
#include <xr/UIOPrivate.h>
#include <xr/Errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/vfs.h>
/*
* The following is the right default for most system calls ...
*/
#define iope0 (&(XR_uioArea->uioa_iope[0]))
static int
XR_DoSysCallInUIOIOP0(iopo, proc)
XR_IOPOrder iopo;
void (*proc)(/* XR_IOPOrder order */);
{
XR_IOPOResult iopoRes;
int result;
iopoRes = XR_IssueIOPOrder(
/*iop*/ iope0,
/*order*/ iopo,
/*proc*/ proc,
/*cancel*/ NIL,
/*abortable*/ FALSE,
/*timeout*/ XR_WAIT_FOREVER
);
if( iopoRes != XR_IOPO_RESULT_OK ) XR_Panic("DoSysCallInUIOIOP0");
result = iopo->iopo_results[0];
if( result < 0 ) {
XR_SetErrno(-result);
return(-1);
}
return result;
}
/*
* access(char *path, int mode)
*/
void
XR_AccessIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_accessPath, NIL);
if( ans >= 0 ) {
ans = access(iopo->iopo_accessPath + ans, iopo->iopo_accessMode);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_Access(path, mode)
char *path;
int mode;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_accessPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_accessMode = (unsigned) mode;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_AccessIOPOrderProc );
}
/*
* int chmod( char *path, int mode)
*/
void
XR_ChModIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_chmodPath, NIL);
if( ans >= 0 ) {
ans = chmod(iopo->iopo_chmodPath + ans, iopo->iopo_chmodMode);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_ChMod(path, mode)
char *path;
int mode;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_chmodPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_chmodMode = (unsigned) mode;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_ChModIOPOrderProc );
}
/*
* int getdomainname(char *name, int namelen)
*/
int
XR_GetDomainName(name, nameLen)
char *name;
int nameLen;
{
int ans;
XR_ProtectSysCall(name, nameLen);
ans = getdomainname(name, nameLen);
XR_UnprotectSysCall();
return(ans);
}
/*
* int getdtablesize()
*/
int
XR_GetDTableSize ()
{
return( XR_uioArea->uioa_numFDE );
}
/*
* int getdtablesize1(XR_FDKind kind)
*/
int
XR_GetDTableSize1 (kind)
XR_FDKind kind;
{
XR_FDE fde, fdeLim;
int n = 0;
fde = XR_uioArea->uioa_fde;
fdeLim = XR_UIOFDELimit;
for( fde = XR_uioArea->uioa_fde; fde < fdeLim; fde++ ) {
if( fde->fde_fdKind == kind ) n++;
}
return( n );
}
/*
* int getnumberoffreefds(XR_FDKind kind)
*/
int
XR_GetNumberOfFreeFDs (kind)
XR_FDKind kind;
{
XR_IOPE iope, iopeLim;
int freeSlots;
freeSlots = 0;
iope = XR_uioArea->uioa_iope;
iopeLim = iope + XR_uioArea->uioa_numIOPE;
while( iope < iopeLim ) {
if( iope->iope_uioFDKind == kind ) freeSlots += iope->iope_uioFreeSlots;
iope++;
}
return freeSlots;
}
/*
* int getgid()
*/
int
XR_GetGID ()
{
return( getgid() );
}
/*
* int getegid()
*/
int
XR_GetEGID ()
{
return( getegid() );
}
/*
* int getgroups(int gidsetlen, int *gidset)
*/
int
XR_GetGroups(gidSetLen, gidSet)
int gidSetLen;
int *gidSet;
{
int ans;
XR_ProtectSysCall(gidSet, gidSetLen * sizeof(int));
ans = getgroups(gidSetLen, gidSet);
XR_UnprotectSysCall();
return(ans);
}
/*
* int gethostid()
*/
int
XR_GetHostID(/* */)
{
return( gethostid() );
}
/*
* int gethostname(char *name, int namelen)
*/
int
XR_GetHostName(name, nameLen)
char *name;
int nameLen;
{
int ans;
XR_ProtectSysCall(name, nameLen);
ans = gethostname(name, nameLen);
XR_UnprotectSysCall();
return(ans);
}
/*
* int getpagesize()
*
* (this is implemented in ThreadsSharemMem.c)
*
int
XR_GetPageSize()
{
return( getpagesize() );
}
*
*/
/*
* int getpgrp(int pid)
*/
int
XR_GetPGrp(pid)
int pid;
{
return( getpgrp(pid) );
}
/*
* int getpid()
*/
int
XR_GetPID()
{
return( XR_sysArea != NIL
? XR_sysArea->sa_vpe[0].vpe_pid
: -1 );
}
/*
* int getppid()
*/
int
XR_GetPPID()
{
return( XR_sysArea != NIL
? XR_sysArea->sa_dbpid
: -1 );
}
/*
* int gettimeofday(struct timeval *tp, struct timezone *tzp)
*/
int
XR_GetTimeOfDay(tp, tzp)
struct timeval *tp;
struct timezone *tzp;
{
struct timeval myT;
struct timezone myTZ;
int ans;
ans = gettimeofday(&myT, &myTZ);
if (tp != NIL) {
*tp = myT;
}
if (tzp != NIL) {
*tzp = myTZ;
}
return(ans);
}
/*
* int getuid()
*/
int
XR_GetUID()
{
return( getuid() );
}
/*
* int geteuid()
*/
int
XR_GetEUID()
{
return( geteuid() );
}
/*
* int kill(int pid, int sig)
*/
int
XR_Kill(pid, sig)
int pid;
int sig;
{
return( kill(pid, sig) );
}
/*
* int killpg(int pgrp, int sig)
*/
int
XR_KillPG(pgrp, sig)
int pgrp;
int sig;
{
return( killpg(pgrp, sig) );
}
/*
* int link(char *name1, char *name2)
* (name1 exists, name2 is created)
*/
void
XR_LinkIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_linkName1, iopo->iopo_linkName2);
if( ans >= 0 ) {
ans = link(iopo->iopo_linkName1+ans, iopo->iopo_linkName2+ans);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_Link(name1, name2)
char *name1;
char *name2;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_linkName1 = (unsigned) XR_UIOFixPathForIOP(name1, iope0);
iopoBuf.iopo_linkName2 = (unsigned) XR_UIOFixPathForIOP(name2, iope0);
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_LinkIOPOrderProc );
}
/*
* int mincore(char *addr, int len, char *vec)
*/
int
XR_MInCore(addr, len, vec)
char *addr;
int len;
char *vec;
{
int ps = XR_GetPageSize();
int ans;
int sz = (len + ps-1)/ps;
XR_ProtectSysCall(vec, sz);
ans = mincore(addr, len, vec);
XR_UnprotectSysCall();
return(ans);
}
/*
* int mkdir(char *path, int mode)
*/
void
XR_MkDirIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_mkdirPath, NIL);
if( ans >= 0 ) {
ans = mkdir(iopo->iopo_mkdirPath + ans, iopo->iopo_mkdirMode);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_MkDir(path, mode)
char *path;
int mode;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_mkdirPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_mkdirMode = (unsigned) mode;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_MkDirIOPOrderProc );
}
/*
* int mknod(char *name, int mode, int dev)
*/
void
XR_MkNodIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_mknodName, NIL);
if( ans >= 0 ) {
ans = mknod(iopo->iopo_mknodName + ans,
iopo->iopo_mknodMode, iopo->iopo_mknodDev);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_MkNod(name, mode, dev)
char *name;
int mode;
int dev;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_mknodName = (unsigned) XR_UIOFixPathForIOP(name, iope0);
iopoBuf.iopo_mknodMode = (unsigned) mode;
iopoBuf.iopo_mknodDev = (unsigned) dev;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_MkNodIOPOrderProc );
}
/*
* int profil(char *buf, int bufSize, int offset, int scale)
*/
void
XR_ProfilVPOrderProc (vpo)
XR_VPOrder vpo;
{
if (XR_OverlapsVDProtected(vpo->vpo_profBuf, vpo->vpo_profBufSize)) {
XR_ConsoleMsg("%? Profile request has heap buffer - ignored\n");
} else {
(void)profil(vpo->vpo_profBuf, vpo->vpo_profBufSize,
vpo->vpo_profOffset, vpo->vpo_profScale);
}
}
void
XR_ProfilIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
XR_VPOrder vpo = &(XR_uioArea->uioa_profVPOrderBuf);
vpo->vpo_profBuf = iopo->iopo_profBuf;
vpo->vpo_profBufSize = iopo->iopo_profBufSize;
vpo->vpo_profOffset = iopo->iopo_profOffset;
vpo->vpo_profScale = iopo->iopo_profScale;
XR_IssueVPOrder(
/*order*/ vpo,
/*proc*/ XR_ProfilVPOrderProc,
/*stop*/ FALSE
);
XR_NotifyIOPODone(iopo);
}
int
XR_Profil(buf, bufSize, offset, scale)
char *buf;
int bufSize;
int offset;
int scale;
{
struct XR_IOPOrderRep iopOrderBuf;
XR_IOPOResult res;
XR_InitIOPOrder(&iopOrderBuf);
iopOrderBuf.iopo_profBuf = ((unsigned)(buf));
iopOrderBuf.iopo_profBufSize = ((unsigned)(bufSize));
iopOrderBuf.iopo_profOffset = ((unsigned)(offset));
iopOrderBuf.iopo_profScale = ((unsigned)(scale));
res = XR_IssueIOPOrder(
/*iop*/ XR_uioArea->uioa_iope,
/*order*/ &iopOrderBuf,
/*proc*/ XR_ProfilIOPOrderProc,
/*cancel*/ NIL,
/*abortable*/ FALSE,
/*timeout*/ XR_WAIT_FOREVER
);
if( res != XR_IOPO_RESULT_OK ) XR_Panic("Profil");
return( 0 );
}
/*
* int readlink(char *path, char *buf, int bufsiz)
*/
void
XR_ReadLinkIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_readlinkPath, NIL);
if( ans >= 0 ) {
ans = readlink(iopo->iopo_readlinkPath + ans,
iopo->iopo_readlinkBuf, iopo->iopo_readlinkBufsiz);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_ReadLink(path, buf, bufsiz)
char *path;
char *buf;
int bufsiz;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_readlinkPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_readlinkBuf = (unsigned) buf;
iopoBuf.iopo_readlinkBufsiz = (unsigned) bufsiz;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_ReadLinkIOPOrderProc );
}
/*
* int rename(char *from, char *to)
*/
void
XR_RenameIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_renameFrom, iopo->iopo_renameTo);
if( ans >= 0 ) {
ans = rename(iopo->iopo_renameFrom+ans, iopo->iopo_renameTo+ans);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_Rename(from, to)
char *from;
char *to;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_renameFrom = (unsigned) XR_UIOFixPathForIOP(from, iope0);
iopoBuf.iopo_renameTo = (unsigned) XR_UIOFixPathForIOP(to, iope0);
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_RenameIOPOrderProc );
}
/*
* int rmdir(char *name)
*/
void
XR_RmDirIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_rmdirName, NIL);
if( ans >= 0 ) {
ans = rmdir(iopo->iopo_rmdirName + ans);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_RmDir(name)
char *name;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_rmdirName = (unsigned) XR_UIOFixPathForIOP(name, iope0);
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_RmDirIOPOrderProc );
}
/*
* int stat(char *path, struct stat *buf)
*/
void
XR_StatIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_statPath, NIL);
if( ans >= 0 ) {
ans = stat(iopo->iopo_statPath + ans, iopo->iopo_statBuf);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_Stat(path, buf)
char *path;
struct stat *buf;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_statPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_statBuf = (unsigned) buf;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_StatIOPOrderProc );
}
/*
* int lstat(char *path, struct stat *buf)
*/
void
XR_LStatIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_lstatPath, NIL);
if( ans >= 0 ) {
ans = lstat(iopo->iopo_lstatPath + ans, iopo->iopo_lstatBuf);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_LStat(path, buf)
char *path;
struct stat *buf;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_lstatPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_lstatBuf = (unsigned) buf;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_LStatIOPOrderProc );
}
/*
* int statfs(char *path, struct statfs *buf)
*/
void
XR_StatFSIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_statfsPath, NIL);
if( ans >= 0 ) {
ans = statfs(iopo->iopo_statfsPath + ans, iopo->iopo_statfsBuf);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_StatFS(path, buf)
char *path;
struct stat *buf;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_statfsPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_statfsBuf = (unsigned) buf;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_StatFSIOPOrderProc );
}
/*
* int symlink(char *name1, char *name2)
* (name1 exists, name2 is created)
*/
void
XR_SymLinkIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_symlinkName2, NIL);
if( ans >= 0 ) {
ans = symlink(iopo->iopo_symlinkName1,
iopo->iopo_symlinkName2+ans);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_SymLink(name1, name2)
char *name1;
char *name2;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_symlinkName1 = (unsigned) XR_UIOFixPathForIOP(name1, iope0);
iopoBuf.iopo_symlinkName2 = (unsigned) XR_UIOFixPathForIOP(name2, iope0);
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_SymLinkIOPOrderProc );
}
/*
* int sync()
*/
int
XR_Sync()
{
return( sync() );
}
/*
* int truncate(char *path, unsigned length)
*/
void
XR_TruncateIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_truncatePath, NIL);
if( ans >= 0 ) {
ans = truncate(iopo->iopo_truncatePath + ans,
iopo->iopo_truncateLength);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_Truncate(path, length)
char *path;
unsigned length;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_truncatePath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
iopoBuf.iopo_truncateLength = (unsigned) length;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_TruncateIOPOrderProc );
}
/*
* int unlink(char *path)
*/
void
XR_UnlinkIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_unlinkPath, NIL);
if( ans >= 0 ) {
ans = unlink(iopo->iopo_unlinkPath + ans);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_Unlink(path)
char *path;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_unlinkPath = (unsigned) XR_UIOFixPathForIOP(path, iope0);
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_UnlinkIOPOrderProc );
}
/*
* int utimes(char *file, struct timeval *tvp)
*/
void
XR_UTimesIOPOrderProc (iopo)
XR_IOPOrder iopo;
{
int ans;
ans = XR_UIOIOPChDirForPaths(iopo->iopo_utimesFile, NIL);
if( ans >= 0 ) {
ans = utimes(iopo->iopo_utimesFile + ans, iopo->iopo_utimesTVP);
if( ans < 0 ) ans = (-errno);
}
iopo->iopo_results[0] = ans;
XR_UIONotifyIOPODone(iopo);
}
int
XR_UTimes(file, tvp)
char *file;
struct timeval *tvp;
{
struct XR_IOPOrderRep iopoBuf;
iopoBuf.iopo_utimesFile = (unsigned) XR_UIOFixPathForIOP(file, iope0);
iopoBuf.iopo_utimesTVP = (unsigned) tvp;
return XR_DoSysCallInUIOIOP0( &iopoBuf, XR_UTimesIOPOrderProc );
}